import request from './request'

// 获取课程分页列表
export const getCoursePage = async (params) => {
  console.log('调用getCoursePage API，参数:', params)
  try {
    const response = await request.get('/student/page', { params })
    console.log('getCoursePage API响应:', response)
    return response
  } catch (error) {
    console.error('getCoursePage API错误:', error)
    // 抛出错误以便调用方处理
    throw error
  }
}

// 选课
export const chooseCourse = async (data) => {
  console.log('调用chooseCourse API，数据:', data)
  try {
    const response = await request.post('/student/choose', data)
    console.log('chooseCourse API响应:', response)
    return response
  } catch (error) {
    console.error('chooseCourse API错误:', error)
    // 抛出错误以便调用方处理
    throw error
  }
}

// 退课
export const dropCourse = (data) => {
  return request.post('/student/reduce', data)
}

// 获取个人课表
export const getClassSchedule = (userId) => {
  return request.get('/student/classSchedule', { params: { userId } })
}